package cn.itrip.biz.service;

import cn.itrip.beans.pojo.ItripHotelOrder;
import cn.itrip.beans.pojo.ItripTradeEnds;
import cn.itrip.dao.ItripHotelOrderMapper;
import cn.itrip.dao.ItripHotelTempStoreMapper;
import cn.itrip.dao.ItripTradeEndsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description :
 * Created by Li on 2021-01-06 16:41:45
 */
@Service
public class TradeEndsService {
    @Autowired
    private ItripTradeEndsMapper tradeEndsMapper;
    @Autowired
    private ItripHotelOrderMapper itripHotelOrderMapper;
    @Autowired
    private ItripHotelTempStoreMapper itripHotelTempStoreMapper;
    public void updateFlag(Map<String, Object> params) {
        tradeEndsMapper.updateFlag(params);
    }
    @Transactional
    public void tradeEnd() {
        Map<String, Object> params = new HashMap<>();
        params.put("newFlag",1);
        params.put("oldFlag",0);
        updateFlag(params);
        List<ItripTradeEnds> list = tradeEndsMapper.selectByFlag(1);
        list.forEach(tradeEnds ->{
            ItripHotelOrder order = itripHotelOrderMapper.selectByOrderNo(tradeEnds.getOrderNo());
            Map<String, Object> roomStoreMap = new HashMap();
            roomStoreMap.put("startTime", order.getCheckInDate());
            roomStoreMap.put("endTime", order.getCheckOutDate());
            roomStoreMap.put("count", order.getCount());
            roomStoreMap.put("roomId", order.getRoomId());
            itripHotelTempStoreMapper.updateRoomStore(roomStoreMap);
        });
        params.put("newFlag", 2);
        params.put("oldFlag", 1);
        updateFlag(params);
    }
}
